package com.easybuilder.game.netty.handler;

import com.alibaba.fastjson.JSONObject;
import com.easybuilder.common.utils.SpringUtil;
import com.easybuilder.common.utils.StringUtil;
import com.easybuilder.core.im.netty.websocket.WebsocketContext;
import com.easybuilder.game.dto.cs.PersonDTO;
import io.netty.channel.Channel;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.SimpleChannelInboundHandler;
import io.netty.handler.codec.http.websocketx.TextWebSocketFrame;


public class CsgoHandler extends SimpleChannelInboundHandler<TextWebSocketFrame> {

    @Override
    protected void channelRead0(ChannelHandlerContext channelHandlerContext, TextWebSocketFrame textWebSocketFrame) throws Exception {
        String text = textWebSocketFrame.text();
        if (StringUtil.isNotEmpty(text)) {
            JSONObject.parseObject(text, PersonDTO.class);
        }
    }

    public CsgoHandler() {
        super();
    }


    @Override
    public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception {
        super.exceptionCaught(ctx, cause);
    }

    @Override
    public void handlerAdded(ChannelHandlerContext ctx) throws Exception {

        WebsocketContext.addVisitorChannel(ctx.channel());
    }

    @Override
    public void handlerRemoved(ChannelHandlerContext ctx) throws Exception {
        super.handlerRemoved(ctx);
    }
}
